package com.example.bbs.agent.jdk;


import java.lang.reflect.Proxy;

/**
 * author: VC
 * create: 2021/7/16 9:36
 * version: 1.0.0
 */
public class Main {
    public static void main(String[] args) {
        Student stu = new Student();
        //创建代理对象
        Pay proxyObj = (Pay)Proxy.newProxyInstance(
                Student.class.getClassLoader(),
                Student.class.getInterfaces()
                , new ObjectProxy(stu));

        int money = proxyObj.payMoney();
        System.out.println("张老师收钱:" + money);

        Teacher teahcher = new Teacher();
        //创建代理老师的对象
        proxyObj = (Pay)Proxy.newProxyInstance(
                Teacher.class.getClassLoader(),
                Teacher.class.getInterfaces()
                , new ObjectProxy(teahcher));

        money = proxyObj.payMoney();
        System.out.println("张老师交钱:" + money);
    }
}
